package com.android.pI;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class SelectWkActivity extends Activity {
	
	ListView menuList;
	DataBaseHelper dbh;
	Cursor cursor;
	SimpleCursorAdapter adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		dbh = new DataBaseHelper(this);

		// Setup UI
		setContentView(R.layout.workouts);
		menuList = (ListView) findViewById(R.id.listStatus);

		// Get the data
		cursor = dbh.fetchWks();
		startManagingCursor(cursor);

		// Setup Adapter
		String[] from = { "wk_name" };
		int[] to = { R.id.wk };
		adapter = new SimpleCursorAdapter(this, R.layout.row, cursor, from, to);
		menuList.setAdapter(adapter);

		menuList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
					public void onItemClick(AdapterView<?> parent,
						View itemClicked, int position, long id) {
						Cursor cursor2 = (Cursor) adapter.getItem(position);
						String wkSelected = cursor2.getString(1);
						Intent intent = new Intent();// intent is an envelop
						// arg1 is the current class and arg2 is the class to pass to
						intent.setClass(SelectWkActivity.this,MainActivity.class);					
						// bundle is the letter
						Bundle bundle = new Bundle(); 
						// arg1 is the keyword for the string , arg2 is the sting to pass
						bundle.putString("workout", wkSelected);
						// bundle carries the content to pass
						intent.putExtras(bundle);
						startActivity(intent);}});
	}
}
